#pragma strict
//////////////////////////////////////////////////////
///品质设定
//////////////////////////////////////////////////////
//左上角 位置.
var startX:float = 100;
var startY:float = 10;
var maxWidth:float = 200;
var maxHeight:float = 200;
/** 摄影机 */
var camGO:Transform;
/** 其他对象 */
var otherGo:Transform[];
/** 光线 */
var sunGo:Transform;
//滚动条的位置
private var scrollPos:Vector2;
private var qualityValue:int;
private var isVegetation:boolean;
private var isOpen:boolean;
private var AAValue:int;

//品质列表
private var QualityLevels:QualityLevel[] = [
	QualityLevel.Fastest,
	QualityLevel.Fast,
	QualityLevel.Simple,
	QualityLevel.Good,
	QualityLevel.Beautiful,
	QualityLevel.Fantastic
];
private var AALevels:int[] = [0,2,4,8];
//旧品质等级
private var oldQualityValue:int;
private var oldAAValue:int;
/** 后期效果开关 */
private var isEnableEffect:boolean = true;
/** 影子开关 */
private var isEnableShadow:boolean = true;

function OnGUI(){
	GUILayout.BeginArea(Rect(startX,startY,maxWidth,maxHeight));
		isOpen = GUILayout.Toggle(isOpen,isOpen?SettingsText.strClose:SettingsText.strQualityOpen);
		if(isOpen){
			scrollPos = GUILayout.BeginScrollView(scrollPos,"box");
				GUILayout.Label(SettingsText.strQuality);
				//品质设定
				oldQualityValue = qualityValue;
				qualityValue = GUILayout.HorizontalSlider(qualityValue,0,5);
				if(oldQualityValue != qualityValue){
					SetQuality();
				}
				isVegetation = GUILayout.Toggle(isVegetation,SettingsText.strSoftVegetation);
				//设置,植物
				QualitySettings.softVegetation = isVegetation;
				//AA
				GUILayout.Label(SettingsText.strAA);
				oldAAValue = AAValue;
				AAValue = GUILayout.HorizontalSlider(AAValue,0,3);
				if(oldAAValue != AAValue){
					SetAA();
				}
				if(GUILayout.Button(isEnableEffect? SettingsText.strCloseEffect : SettingsText.strOpenEffect)){
					isEnableEffect = !isEnableEffect;
					ForbiddenEffects();
				}
				if(GUILayout.Button(isEnableShadow?SettingsText.strCloseShadow:SettingsText.strOpenShadow)){
					isEnableShadow = !isEnableShadow;
					ForbiddenShadow();
				}
			GUILayout.EndScrollView();
		}
	GUILayout.EndArea();
}
/** 品质设定 */
private function SetQuality(){
	// QualitySettings.currentLevel = QualityLevels[qualityValue];
	QualitySettings.SetQualityLevel(qualityValue);
}
/** 抗锯齿 */
private function SetAA(){
	QualitySettings.antiAliasing = AALevels[AAValue];
}
/** 禁用效果 */
private function ForbiddenEffects(){
	if(camGO){
		var effects:PostEffectsBase[] = camGO.GetComponents.<PostEffectsBase>();
		for(var effect:PostEffectsBase in effects){
			effect.enabled = isEnableEffect;
		}
		camGO.GetComponent(GlowEffect).enabled = isEnableEffect;
		camGO.GetComponent(SSAOEffect).enabled = isEnableEffect;
	}
	for(var t:Transform in otherGo){
		t.gameObject.SetActive(isEnableEffect);
	}
}

private function ForbiddenShadow(){
	//关闭影子
	if(sunGo){
		var l:Light = sunGo.GetComponent(Light);
			l.shadows = isEnableShadow ? LightShadows.Soft : LightShadows.None;
	}
}